BITS 32
%include "macrosmodoprotegido.mac"

%define color 0x0F

global imprimir_registros

;defines de los nombres de registros
_eax: db 'EAX     '
	eax_len: equ $ - _eax
_ebx: db 'EBX     '
	ebx_len: equ $ - _ebx
_ecx: db 'ECX     '
	ecx_len: equ $ - _ecx
_edx: db 'EDX     '
	edx_len: equ $ - _edx
_esi: db 'ESI     '
	esi_len: equ $ - _esi
_edi: db 'EDI     '
	edi_len: equ $ - _edi
_ebp: db 'EBP     '
	ebp_len: equ $ - _ebp
_esp: db 'ESP     '
	esp_len: equ $ - _esp
_cr0: db 'CR0     '
	cr0_len: equ $ - _cr0
_cr2: db 'CR2     '
	cr2_len: equ $ - _cr2
_cr3: db 'CR3     '
	cr3_len: equ $ - _cr3
_cr4: db 'CR4     '
	cr4_len: equ $ - _cr4
eflags: db 'EFLAGS  '
	eflags_len: equ $ - eflags
_cs: db 'CS    '
	cs_len: equ $ - _cs
_ds: db 'DS    '
	ds_len: equ $ - _ds
_es: db 'ES    '
	es_len: equ $ - _es
_fs: db 'FS    '
	fs_len: equ $ - _fs
_gs: db 'GS    '
	gs_len: equ $ - _gs
_ss: db 'SS    '
	ss_len: equ $ - _ss
_stack: db 'stack'
	stack_len: equ $ - _stack
buffer_hex: dq 0
eax_temp: dd 0

col1 equ 43
col2 equ 60
fil1 equ 3

imprimir_registros:
;imprimo EAX
	IMPRIMIR_TEXTO $_eax, eax_len, color, fil1, col1
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, fil1, (col1+eax_len)
;imprimo EBX
	IMPRIMIR_TEXTO $_ebx, ebx_len, color, (fil1+1), col1
	DWORD_TO_HEX ebx, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+1), (col1+ebx_len)	
;imprimo ECX	
	IMPRIMIR_TEXTO $_ecx, ecx_len, color, (fil1+2), col1
	DWORD_TO_HEX ecx, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+2), (col1+ecx_len)
;imprimo EDX
	IMPRIMIR_TEXTO $_edx, edx_len, color, (fil1+3), col1
	DWORD_TO_HEX edx, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+3), (col1+edx_len)
;imprimo ESI
	IMPRIMIR_TEXTO $_esi, esi_len, color, (fil1+4), col1
	DWORD_TO_HEX esi, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+4), (col1+esi_len)
;imprimo EDI
	IMPRIMIR_TEXTO $_edi, edi_len, color, (fil1+5), col1
	DWORD_TO_HEX edi, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+5), (col1+edi_len)
;imprimo EBP
	IMPRIMIR_TEXTO $_ebp, ebp_len, color, (fil1+6), col1
	DWORD_TO_HEX ebp, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+6), (col1+ebp_len)
;me guardo eax, porque es el que voy a usar para ir imprimiendo los demas registros
	mov [eax_temp], eax
;imprimo ESP
	IMPRIMIR_TEXTO $_esp, esp_len, color, (fil1+7), col1
	lea eax,[esp+4]			; usamos lea para sumar 4 por el call sin modificar eflags
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+7), (col1+esp_len)
;imprimo CR0
	mov eax,cr0
	IMPRIMIR_TEXTO $_cr0, cr0_len, color, (fil1+8), col1
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+8), (col1+cr0_len)
;imprimo CR2
	mov eax,cr2	
	IMPRIMIR_TEXTO $_cr2, cr2_len, color, (fil1+9), col1
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+9), (col1+cr2_len)
;imprimo CR3
	mov eax,cr3	
	IMPRIMIR_TEXTO $_cr3, cr3_len, color, (fil1+10), col1
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+10), (col1+cr3_len)
;imprimo CR4
	mov eax,cr4	
	IMPRIMIR_TEXTO $_cr4, cr4_len, color, (fil1+11), col1
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+11), (col1+cr4_len)
;imprimo EFLAGS
	mov eax,0
	lahf
	IMPRIMIR_TEXTO $eflags, eflags_len, color, (fil1+12), col1
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+12), (col1+eflags_len)
;imprimo CS
	mov eax,0
	mov ax,cs
	IMPRIMIR_TEXTO $_cs, cs_len, color, fil1, col2
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, fil1, (col2+cs_len)
;imprimo DS
	mov eax,0
	mov ax,ds
	IMPRIMIR_TEXTO $_ds, ds_len, color, (fil1+1), col2
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+1), (col2+ds_len)
;imprimo ES
	mov eax,0
	mov ax,es
	IMPRIMIR_TEXTO $_es, es_len, color, (fil1+2), col2
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+2), (col2+es_len)
;imprimo FS
	mov eax,0
	mov ax,fs
	IMPRIMIR_TEXTO $_fs, fs_len, color, (fil1+3), col2
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+3), (col2+fs_len)
;imprimo GS
	mov eax,0
	mov ax,gs
	IMPRIMIR_TEXTO $_gs, gs_len, color, (fil1+4), col2
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+4), (col2+gs_len)
;imprimo SS
	mov eax,0
	mov ax,ss
	IMPRIMIR_TEXTO $_ss, ss_len, color, (fil1+5), col2
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+5), (col2+ss_len)
;imprimo titulo para stack
	IMPRIMIR_TEXTO $_stack, stack_len, color, (fil1+6), col2
;imprimo stack1
	mov eax, [esp+4]
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+7), col2
;imprimo stack2
	mov eax, [esp+8]
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+8), col2
;imprimo stack3
	mov eax, [esp+12]
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+9), col2
;imprimo stack4
	mov eax, [esp+16]
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+10), col2
;imprimo stack5
	mov eax, [esp+20]
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+11), col2
;imprimo stack6
	mov eax, [esp+24]
	DWORD_TO_HEX eax, buffer_hex
	IMPRIMIR_TEXTO buffer_hex, 8, color, (fil1+12), col2

;vuelvo a recuperar EAX antes de salir
	mov eax,[eax_temp]
	ret
